//
//  CTChargeALiPayViewController.m
//  CT
//
//  Created by liufanwei on 15/4/6.
//  Copyright (c) 2015年 liufanwei. All rights reserved.
//

#import "CTChargeALiPayViewController.h"
#import "BDKNotifyHUD.h"
#import "CTChargeWebViewController.h"
#import "CTUserDefaultHelper.h"
#import "CTNetHelper.h"
#import "CommonMicro.h"
#import "UILabel+WBExtension.h"

@interface CTChargeALiPayViewController ()
@property (weak, nonatomic) IBOutlet UITextField *Money;
@property (weak, nonatomic) IBOutlet UITextField *Number;

@end

@implementation CTChargeALiPayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _Money.layer.masksToBounds=YES;
    _Money.layer.borderColor= [kRGB(13, 167, 211) CGColor];
    _Money.layer.borderWidth= 2.0f;
    _Money.keyboardType = UIKeyboardTypeDecimalPad;
    
    _Number.text = [NSString stringWithFormat:@"%@",[[CTUserDefaultHelper ShareInstance] Account]];
    _Number.layer.masksToBounds=YES;
    _Number.layer.borderColor= [kRGB(13, 167, 211) CGColor];
    _Number.layer.borderWidth= 2.0f;
    _Number.keyboardType = UIKeyboardTypeNumberPad;
    
    UILabel * titleLabel = [UILabel labelWithText:@"支付宝在线充值" font:[UIFont fontWithName:kFontName size:20]];
    titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titleLabel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (IBAction)onSureClick:(id)sender {
    NSString * acc = _Number.text;
    if (acc.length != 11 ||  acc.integerValue == 0) {
        [BDKNotifyHUD notifyHUDWithText:@"输入账号有误"];
        return;
    }
    if([_Money.text floatValue] == 0){
        [BDKNotifyHUD notifyHUDWithText:@"金额有误重新输入"];
        return;
    }
    [self performSegueWithIdentifier:@"alipaytowebview" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSString * acc = _Number.text;
    NSString * number = _Money.text;
    NSString * key =[NSString stringWithFormat:@"WIDout_trade_no=%@_%@&WIDsubject=ZYTAlipay-IOS&WIDtotal_fee=%@",acc,number,number];
    NSString * url = [NSString stringWithFormat:@"%@alipay/alipayapi.jsp?%@",kBaseUrl,key];
    CTChargeWebViewController * vc = segue.destinationViewController;
    vc.Url = url;
}

@end
